package 作业;
import java.io.*;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class 作业4 {
    public static void main(String[] args) throws IOException {
        File file1 = new File("c:/yc123");
        File file2 = new File("c:/yc123/张三");
        File file3 = new File("c:/yc123/李四");
        File file4 = new File("c:/yc123/谢康");
        File file5 = new File("c:/yc123/张三", "张三的个人信息.txt");

        file5.createNewFile();
        File file6 = new File("c:/yc123/李四", "李四的个人信息.txt");
        file5.renameTo(file6);

        File file7 = new File("c:/yc123/谢康", "谢康的个人信息");
        file7.createNewFile();

        FileOutputStream fos= new FileOutputStream("c://yc123");
        DataOutputStream dos = new DataOutputStream(fos);
        try {
            dos.writeUTF("谢康  20  21010540117");
        } finally {
            dos.close();
        }

        FileInputStream fis = new FileInputStream("c://yc123");
        DataInputStream d2 = new DataInputStream(fis);

        try {
            System.out.println(d2.readUTF());

        } finally {

            d2.close();
        }

        File f1 = new File("c:\\Windows");
        FilenameFilter ff = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                return name.endsWith(",txt") || name.endsWith(".exe") || name.endsWith("bat");

            }

        };
        File[] f1s = f1.listFiles(ff);
        for (File f : f1s) {
            Date date = new Date(f.lastModified());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日  HH:mm:ss");
            System.out.println(f.getName() + "\t" + f.length() + "\t" + sdf.format(date));
        }
        System.out.println("===================");
        File [ ] f2s=f1.listFiles(pathname->{
            Date date = new Date(pathname.lastModified());
            Calendar cal = Calendar.getInstance();
            cal.setTime(date);
            return cal.get(Calendar.YEAR)==2021;
        });

        for (File f : f2s) {
            Date date = new Date(f.lastModified());
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日  HH:mm:ss");
            System.out.println(f.getName() + "\t"   + sdf.format(date));
        }

        System.out.println("===============");
        File [ ] f3s=f1.listFiles(pathname->{
            return ((1024*10<pathname.length( ))&&(pathname.length( )<1024*1024*5));
        });

        for(File f:f3s){
            System.out.println(f.getName()+"\t"+f.length());
        }

    }
}